package com.Action;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.Action.*;
import com.jdbc.*;
import com.project.bean.*;
import org.apache.commons.io.FileUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.util.CellRangeAddress;

public class ContractModel {

    public ContractModel() {
    	
    
		
	//ContractTemplate ct =new ContractTemplate();
	
		//引入需要解析的EXCEL文件
	//String path = ct.filepath;
        String headline="合同信息";
		String[] title= {"合同ID","学生编号","中文名","英文名","性别","出生日期","课程名","总课时","剩余课时","学费","收费情况","签约类型","课程顾问","电话顾问","DEMO中教","DEMO外教"};
		//创建EXCEL工作簿
			HSSFWorkbook workbook = new HSSFWorkbook();
			//创建一个工作sheet
			HSSFSheet sheet = workbook.createSheet();
			CellStyle cellStyle = workbook.createCellStyle();
			DataFormat format = workbook.createDataFormat();  
			cellStyle.setDataFormat(format.getFormat("@"));
			//sheet.setDefaultColumnStyle(column, style);
			//创建第一行
			HSSFRow row = sheet.createRow(0);
			HSSFCell cell = null ;
			//创建标题
			sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 2));
			cell =row.createCell(0);
			cell.setCellValue(headline);
			//创建第二行
			HSSFRow rowtitle = sheet.createRow(1);
			//插入第二行title 
			for(int i=0;i<title.length;i++) {
			sheet.setDefaultColumnStyle(i, cellStyle);
			cell =rowtitle.createCell(i);
			cell.setCellValue(title[i]);
			}
			//追加数据,1先从数据库中获取结果集并且放到LIST中，然后一行一行地放入
			
			
			//创建一个文件
			File file = new File("/Users/duyifan/Desktop/contractModel.xls");
			
			try {
				file.createNewFile();
				//将EXCELL内容存盘
				FileOutputStream stream = FileUtils.openOutputStream(file);
				workbook.write(stream);
				stream.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}

}


